|
|
|
|
|
|
|
Unloading an MDI Application |
|
|
|
|
|
|
|
|
To unload an MDI application, you simply need to unload the MDI form. In the File, Exit menu, place the following code: |
|
|
|
 |
|
|
|
|
Private Sub mnuFExit_Click()
Unload Me
End Sub |
|
|
|
|
|
|
|
|
This causes the parent MDI form to unload. When the parent form unloads, any open child forms must also unload. This little bit of code causes everything to be unloaded and your application to be shut down. |
|
|
|
|
|
|
|
|
If the user starts to edit information on a child form and then attempts to close the MDI parent form, the child form has the ability to stop the parent from unloading while in this edit mode. Of course, its up to the child form to inform the parent that it cannot close right now. You write this type of code in the child forms QueryUnload event. Heres an example: |
|
|
|
 |
|
|
|
|
Private Sub Form_QueryUnload(Cancel As Integer, _
UnloadMode As Integer)
If cmdSave.Enabled Then
MsgBox "Changes on the Employee form " & _
"have not been saved. Please save " & _
"prior to unloading application"
Cancel = True End If
End Sub |
|
|
|
|
|
|
|
|
When a form is about to unload, it invokes the forms QueryUnload event. Visual Basic passes in a Cancel parameter by reference so that you can set this Cancel flag to True if you want to stop the unloading of the form. In a Chapter 25, Data Entry with ADO Objects, youll learn a technique for asking the user whether he or she wants to save the changes prior to unloading the form. |
|
|
|
|
|